<?php

namespace Proj\ResManBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

class ResourcesRepository extends EntityRepository
{
    public function findByPerson($person) {
        $qb = $this->createQueryBuilder('r')
                   ->select('r')
                   ->join('r.taskResources', 'tr')
                   ->join('tr.task', 't')
                   ->join('t.people', 'pe')
                   ->where('pe.id = :personId')->setParameter('personId', $person->getId())
                   ->groupBy('r.id');

        return $qb->getQuery()
                  ->getResult();
    }
    
    public function findByProject($project) {
        $qb = $this->createQueryBuilder('r')
                   ->select('r')
                   ->join('r.taskResources', 'tr')
                   ->join('tr.task', 't')
                   ->join('t.activity', 'a')
                   ->join('a.project', 'p')
                   ->where('p.id = :projectId')->setParameter('projectId', $project->getId())
                   ->groupBy('r.id');

        return $qb->getQuery()
                  ->getResult();
    }
}